@extends('admin.pop_edit')
@section('body')
    <form id="systemUserEditForm" lay-filter="systemUserEditForm" action="{{admin_url($baseRoute.'update')}}"
          class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">@lang('system.role.group_name'):</label>
                <div class="layui-input-block">
                    @include('admin.system.widget.group_select',['widget_params'=>['showAll'=>false]])
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">@lang('system.user.role'):</label>
                <div class="layui-input-block">
                    <select name="role_id" id="sltRole" class="select">
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">@lang('system.user.username'):</label>
                <div class="layui-input-block">
                    <input type="text" name="username" placeholder="@lang('system.user.tips.username')"
                           class="layui-input"
                           lay-verType="tips" lay-verify="required" required/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="name" placeholder="请输入名称"
                           class="layui-input"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">手机号:</label>
                <div class="layui-input-block">
                    <input type="text" name="mobile" placeholder="请输入手机号" class="layui-input"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">@lang('system.user.password'):</label>
                <div class="layui-input-block">
                    <input type="text" name="password" placeholder="@lang('system.user.tips.password')"
                           class="layui-input"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">@lang('system.index.password_confirmation'):</label>
                <div class="layui-input-block">
                    <input type="text" name="password_confirmation"
                           placeholder="@lang('system.index.tips.password_confirmation')" class="layui-input"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label layui-form-required">所属部门:</label>
            <div class="layui-input-block">
                <x-system.department name="department_id"></x-system.department>
            </div>
        </div>
        <div class="layui-form-item" id="lfiHospital">
            <label class="layui-form-label layui-form-required">医院:</label>
            <div class="layui-input-block">
                <x-system.hospital name="hospital_ids[]" :value="$entity['hospital_ids']"></x-system.hospital>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="ajaxForm" lay-submit>@lang('common.save')</button>
            <button class="layui-btn layui-btn-primary" type="button"
                    ew-event="closeDialog">@lang('common.cancel')</button>
        </div>
    </form>
@stop
@push('script')
    <script type="text/javascript">
        layui.use('form', function () {
            layui.form.val('systemUserEditForm', {!! json_encode($entity) !!});
            layui.form.on('select(group_code)', function (item) {
                group_code_change(item.value);
            });

            function group_code_change(value) {
                if (value === "{{\App\Models\System\Group::PLAT}}") {
                    layui.$('#lfiHospital').hide();
                } else {
                    layui.$('#lfiHospital').show();
                }
                SystemUtil.ajax("{{admin_url('system/role/load')}}", "GET")
                    .setData({group_code: value})
                    .send(1)
                    .done(function (res) {
                        var html = "";
                        res.data.forEach(function (item) {
                            html = html + "<option value='" + item.id + "'>" + item.name + "</option>";
                        });
                        layui.$('#sltRole').html(html);
                        layui.$('#sltRole').val({{$entity['role_id']}});
                        layui.form.render("select");
                    });
            }

            group_code_change(layui.$('#group_code').val());
        });
    </script>
@endpush
